<?php
/**
 * Created by PhpStorm.
 * User: Core
 * Date: 2018/3/12
 * Time: 11:07
 */

namespace App\models;


use App\Libs\ApiMessage;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class LuckMoney extends Model
{
    protected $table="luckmoney"; // 数据库表
    protected $dateFormat = 'U'; // 时间戳

    // 搜索活动信息
    public static function get_activity_info($id) {
        if(!empty($id)){
            $data = DB::table('luckmoney')
                ->select('*')
                ->where(function($query)use($id){
                    $query -> where('id', $id);
                })->first();
            return $data;
        }
    }

    public function get_luck_money_by_id($id) {
        return $this->find($id,['id','money','share_number','start_time','end_time','title_array']);
    }


    public function get_total_activity_by_id($aid) {
        return $this->find($aid);
    }

    public function update_used_by_id($aid) {
        return DB::table($this->table)->where(['id'=>$aid])->increment("use_number",1);
    }

    public function get_activity_info_by_id($id) {
        $info = $this->find($id,['info']);
        $message = new ApiMessage();
        $message->setCode(ApiMessage::SUCCESS);
        $message->setData(['info'=>$info->info]);
        return $message;
    }
}